//
//  SellingViewController.m
//  WestAir
//
//  Created by 张燕枭 on 16/8/28.
//  Copyright © 2016年 张燕枭. All rights reserved.
//

#import "SellingViewController.h"
#import "SaleShoppingCart.h"
#import "Reamark.h"
#import "ClassifiCation.h"
#import "HomeViewController.h"

@interface SellingViewController ()<sellingCellDeleget,UITextFieldDelegate,UIScrollViewDelegate>{
    
    
    __weak IBOutlet UITableView *sale_tableView;
    BOOL  isSearch;
    
}


@property(nonatomic,strong)NSMutableArray  *arrMainData;
@property(nonatomic,strong)NSMutableArray  *arrZiTi;
@property(nonatomic,strong)NSMutableArray  *arrYouGou;
@property(nonatomic,strong)NSMutableArray  *arrSearch;

@property(nonatomic,strong)NSMutableArray  *arrGouWu;
@property (weak, nonatomic) IBOutlet UITextField *textContent;

@end

@implementation SellingViewController
@synthesize arrMainData,arrGouWu,arrZiTi,arrYouGou ;


#pragma mark 数据整理及初始化界面

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupSearchBar];
    [self  getData];
    
    [[NSNotificationCenter     defaultCenter] addObserver:self selector:@selector(textDidChange:) name:UITextFieldTextDidChangeNotification object:_textContent];
    
    
    
}

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    
}

- (void)setupSearchBar
{
    self.type=xianXiao;
    arrGouWu=[NSMutableArray  new];
    arrMainData  =[NSMutableArray new];
    arrYouGou=[NSMutableArray new];
    arrZiTi=[NSMutableArray new];
    _arrSearch=[NSMutableArray  new];
    
    UIButton  *btnLef=[[UIButton  alloc]  initWithFrame:CGRectMake(0, 0, 38, 38)];
    [btnLef setImageEdgeInsets:UIEdgeInsetsMake(8, 8, 8, 8)];
    [btnLef setImage:[UIImage imageNamed:@"sousuo_tb"] forState:UIControlStateNormal];
    
    
    _textContent.leftView=btnLef;
    _textContent.leftViewMode=UITextFieldViewModeAlways;
    
    
}

-(void)getData{
    
    [_textContent resignFirstResponder];
    _textContent.text=@"";
    isSearch=NO;
    
    // 每次清空数据
    [self.arrMainData removeAllObjects];
    [self.arrZiTi  removeAllObjects];
    [self.arrYouGou  removeAllObjects];
    
    [self getXianXiaoAndYouJi];
    
    [self  getZiTiData];
    
    [self  isShoppingID];
    
}

-(void)isShoppingID{
    
    HangBanInfo  *currentHangBan=[HangBanInfo  currentHangBan];
    NSString  *flightNumber=currentHangBan.FFLIGHTNUMBER;
    NSString  *flightDate=currentHangBan.FFLIGHTDATE;
    NSDictionary  *dicJson= [CMCCIOTIGUnity   getRequestJson:@{@"FFLIGHTNUMBER":flightNumber,@"FFLIGHTDATE":flightDate}];
    NSString  *ddd=[CMCCIOTIGUnity getJons:dicJson];
    
    [[NetworkFactory  alloc]  startPostRequestWithURL:IsExsitShoppingCart andPostValues:dicJson andSuccessBlock:^(NSDictionary *responseJson) {
        
        if ([responseJson[@"IsSuccess"]  integerValue]==1) {
            
            [HangBanInfo currentHangBan].shoppingCartID=[NSString stringWithFormat:@"%@",responseJson[@"ShoppingCartID"]];
            
        }
      
        
    } andFailBlock:^(NSError *error) {
        
        
    } ];
    
    
}

// 获取 现销和邮寄

-(void)getXianXiaoAndYouJi{
    
    NSString  *priceListNo=[HangBanInfo currentHangBan].priceListNo;
    NSDictionary  *dicJson=  [CMCCIOTIGUnity   getRequestJson:@{@"priceListNo":priceListNo}];
    
    [[NetworkFactory  alloc]  startPostRequestWithURL:GETPRODUCTLIST andPostValues:dicJson andSuccessBlock:^(NSDictionary *responseJson) {
        
        if ([responseJson[@"IsSuccess"]  integerValue]==1) {
            
            NSArray  *arrData;
            if ([responseJson[@"data"] isKindOfClass:[NSArray class]]) {
                arrData=responseJson[@"data"] ;
            }
            else{
                arrData=@[];
                
            }
            [arrData  enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                
                NSDictionary  *dicData=obj;
                
                Product *product=[[Product  alloc]  init];
                [product setProduct:dicData type:@"1"];
                [arrMainData  addObject:product];
                
                Product *productYouGou=[[Product  alloc]  init];
                [productYouGou setProduct:dicData type:@"3"];
                [arrYouGou  addObject:productYouGou];
                
            }];
            [sale_tableView reloadData];
        }
        else{
            
        }
    } andFailBlock:^(NSError *error) {
        [sale_tableView reloadData];
        
    } ];
    
}

//  自提
-(void)getZiTiData{
    
    
    NSMutableDictionary  *dicParama=[NSMutableDictionary  new];
    [dicParama setObject:[HangBanInfo  currentHangBan].FFLIGHTNUMBER forKey:@"FNUMBER"];
    [dicParama  setObject:[HangBanInfo  currentHangBan].FFLIGHTDATE forKey:@"FFLIGHTDATE"];
    NSDictionary  *desStr= [CMCCIOTIGUnity   getRequestJson:dicParama];
    
    
    [[NetworkFactory  alloc]  startPostRequestWithURL:GETPRODUCZiTi andPostValues:desStr andSuccessBlock:^(NSDictionary *responseJson) {
        
        
        if ([responseJson[@"IsSuccess"]  integerValue]==1) {
            
            NSArray  *arrData;
            if ([responseJson[@"data"] isKindOfClass:[NSArray class]]) {
                arrData=responseJson[@"data"] ;
            }
            else{
                
                arrData=@[];
                
            }
            
            [arrData  enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                
                NSDictionary  *dicData=obj;
                
                Product *product=[[Product  alloc]  init];
                product.FCatogeryID=[dicData[@"FCatogeryID"]  integerValue];product.FID=[STRING_FORMAT(dicData[@"FID"]) integerValue];
                product.FNumber=[dicData[@"FNumber"]  nullClass];
                product.FUSERNAME=[dicData[@"FUSERNAME"]  nullClass];
                product.FName=[dicData[@"FName"]  nullClass];
                product.FQty=[dicData[@"FQty"] integerValue];
                product.FPrice=[[STRING_FORMAT(dicData[@"FPrice"])   nullClass]  floatValue];
                
                product.FIDCARD=[[STRING_FORMAT(dicData[@"FIDCARD"])   nullClass]  integerValue];
                product.ImageUrl=[dicData[@"ImageUrl"]  nullClass];
                
                product.FSaleType=@"2";
                
                [arrZiTi addObject:product];
                
            }];
            
            [sale_tableView reloadData];
            
            
        }
       
        
        
    } andFailBlock:^(NSError *error) {
        
        
    } ];
    
    
}

#pragma mark 常用方法

-(NSMutableArray  *)getCurrentData{
    
    NSMutableArray  *arrData;
    if (isSearch) {
        arrData=_arrSearch;
    }
    else{
        if (self.type==xianXiao) {
            arrData=arrMainData;
        }
        else if(self.type==ziTi){
            arrData=arrZiTi;
            
        }
        else{
            arrData=arrYouGou;
        }
    }
    return arrData;
}
-(void)modifyCurrentData{
    
    NSArray  *arrGouWuParama=[self  getCurrentData];
    // 先筛选数量大于0
    [arrGouWuParama enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        Product  *product=(Product *)obj;
        if (product.FQty>0) {
            product.FQty=0;
        };
    }];
    [sale_tableView  reloadData];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark tableView  deleget

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (!isSearch) {
        
        if (self.type==xianXiao) {
            return arrMainData.count;
        }
        else if(self.type==ziTi){
            
            return arrZiTi.count;
        }
        else{
            return arrYouGou.count;
        }
        
        ;
    }
    else{
        
        return   _arrSearch.count;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    if (self.type!=ziTi) {
        SellingCell    *cell=[tableView dequeueReusableCellWithIdentifier:@"SellingList"];
        cell.delegate=self;
        Product   *product;
        NSMutableArray  *arrData=[self getCurrentData];
        product=arrData[indexPath.row];
        
        Reamark  *remarkTem=product.remark;
        if (remarkTem) {
            cell.TextViewContent.text=[NSString stringWithFormat:@"%@：%@，%@：%@，%@：%@，%@：%@",@"姓名",remarkTem.FCustomerName?remarkTem.FCustomerName:@"",@"联系方式", remarkTem.FCustomerTel,@"座位号", remarkTem.FCustomerSeatNum,@"地址", remarkTem.FCustomerAddress] ;
        }
        else{
            cell.TextViewContent.text=product.FRemark;
        }
        cell.TextViewContent.hidden=YES;
        cell.viewLine.hidden=YES;
        
        cell.lableTitle.text=product.FName;
        cell.currentIndex=indexPath.row;
        NSString  *strPrice= [NSString stringWithFormat:@"¥%.1f",product.FPrice];
        CGSize  lableSize = [CMCCIOTIGUnity  getSize:strPrice andSize:CGSizeMake(MAXFLOAT, cell.lablePrice.heightV)  and:cell.lablePrice.font];
        cell.lableNum.text=[NSString stringWithFormat:@"%ld",(long)product.FQty];
        cell.lablePrice.text=strPrice;
        
        cell.lablePriceWidth.constant=lableSize.width+5;
        NSString  *imageUrl=product.ImageUrl;
        
        
        [cell.iamgeHead  sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"default"]];
        
        if ([[HangBanInfo  currentHangBan].FIsAuthorize  isEqualToString:@"0"]) {
            cell.btnEdit.hidden=YES;
        }  ;
        
        cell.modle=product;
        return cell;
        
    }
    else{
        
        SellingCellZiTi    *cell=[tableView dequeueReusableCellWithIdentifier:@"SellingListZiTi"];
        cell.delegate=self;
        Product   *product;
        NSMutableArray  *arrData=[self getCurrentData];
        product=arrData[indexPath.row];
        
        Reamark  *remarkTem=product.remark;
        if (remarkTem) {
            cell.TextViewContent.text=[NSString stringWithFormat:@"%@：%@，%@：%@，%@：%@，%@：%@",@"姓名",remarkTem.FCustomerName?remarkTem.FCustomerName:@"",@"联系方式", remarkTem.FCustomerTel,@"座位号", remarkTem.FCustomerSeatNum,@"地址", remarkTem.FCustomerAddress] ;
        }
        else{
            cell.TextViewContent.text=product.FRemark;
        }
        cell.lableName.text=[NSString stringWithFormat:@"姓名: %@",product.FUSERNAME];
        cell.bodyNumber.text=[NSString stringWithFormat:@"证件号: %ld",(long)product.FIDCARD];
        cell.lableTitle.text=product.FName;
        cell.currentIndex=indexPath.row;
        NSString  *strPrice= [NSString stringWithFormat:@"¥%.1f",product.FPrice];
        cell.lableNum.text=[NSString stringWithFormat:@"%ld",(long)product.FQty];
        cell.lablePrice.text=strPrice;
        
        cell.modle=product;
        return cell;
        
        
    }
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (self.type==xianXiao) {
        return 124;
        
    }
    else if (self.type==ziTi){
        return 140;
        
    }
    else{
        return 124;
        
    }
    
}

// 返回
- (IBAction)popBack:(id)sender {
    
    for (UIViewController  *viewTem  in self.navigationController.viewControllers) {
        if ([viewTem isKindOfClass:[HomeViewController class]]) {
            [self.navigationController  popToViewController:viewTem animated:YES];
            break;
        }
        
        
        ;
    }
    
    [[NSNotificationCenter     defaultCenter] removeObserver:self];
    
}


#pragma mark cell delegate

-(void)modifyNumber:(NSInteger  )index and:(Product  *)modle{
    
    [self  repalce:index  and:modle];
}
-(void)modifyBeiZhu:(NSInteger)index and:(Product  *)modle{
    [self  repalce:index  and:modle];
}
-(void)modifyPrice:(NSInteger)index and:(Product  *)modle{
    [self  repalce:index  and:modle];
    
}

-(void)repalce:(NSInteger  )index  and:(Product  *)modle{
    
    if (!isSearch) {
        if (self.type==xianXiao) {
            [arrMainData  replaceObjectAtIndex:index withObject:modle];
        }
        else if(self.type==ziTi){
            [arrZiTi  replaceObjectAtIndex:index withObject:modle];
        }
        else{
            [arrYouGou  replaceObjectAtIndex:index withObject:modle];
        }
        
    }
    else{
        
        [_arrSearch  replaceObjectAtIndex:index withObject:modle];
        
    }
}
-(void)becomeEditing:(NSInteger)index {
    
    float heightForRow=0;
    
    if (self.type==xianXiao) {
        heightForRow=154;
    }
    else if(self.type==ziTi){
        heightForRow=140;
    }
    else{
        heightForRow=124;
        
    }
    
    NSMutableArray  *arrData;
    if (!isSearch) {
        if (self.type==xianXiao) {
            arrData=arrMainData;
        }
        else if(self.type==ziTi){
            arrData=arrMainData;
            ;
        }
        else{
            arrData=arrMainData;
        }
        
    }
    else{
        
        arrData=arrMainData;
        
    }
    if ( (SCREEN_HEIGHT-270)<(110+(index+1)*heightForRow-sale_tableView.contentOffset.y)) {
        [sale_tableView setContentOffset:CGPointMake(sale_tableView.contentOffset.x, 110+(index+1)*heightForRow-SCREEN_HEIGHT+270) ] ;
    }
    
}

#pragma mark  textField delegate

-(void)textDidChange:(NSNotification *)object{
    
    UITextField  *text= [object  object];
    NSString  *searchStr=text.text;
    NSMutableArray  *arrData;
    if (self.type==xianXiao) {
        arrData=arrMainData;
    }
    else if(self.type==xianXiao){
        arrData=arrZiTi;
    }
    else{
        arrData=arrYouGou;
    }
    
    if (searchStr.length==0) {
        isSearch=NO;
        [sale_tableView  reloadData];
    }
    else{
        
        NSMutableArray  *arrSearch=[NSMutableArray  new];
        [arrData  enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            Product  *product=obj;
            NSString *name=product.FName;
            if ([name  containsString: searchStr]  ) {
                [arrSearch  addObject:product];
            }
        }];
        isSearch=YES;
        _arrSearch=arrSearch;
        [sale_tableView  reloadData];
    }
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    return YES;
}

#pragma mark 页面跳转及事件点击
- (IBAction)pushToGouWuChe:(id)sender {
    
    if ([[HangBanInfo  currentHangBan].FSubmitSalOrder  isEqualToString:@"1"]) {
        [CMCCIOTTipsCenter  showErrorWithStatus:@"订单已经提交"];
        return;
    }
    [self.arrGouWu removeAllObjects];
    //添加商品到购物车
    NSMutableArray  *arrGouWuParama=[self getCurrentData];
    
    // 先筛选数量大于0
    NSMutableArray  *arrGouWuFQty=[NSMutableArray new];
    [arrGouWuParama enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        Product  *product=(Product *)obj;
        if (product.FQty>0) {
            [arrGouWuFQty addObject:product];
        }
        ;
    }];
    
    if (arrGouWuFQty.count) {
        Product *product=arrGouWuFQty[0];
        if ([product.FSaleType isEqualToString:@"3"]) {
            NSMutableArray  *arrTextField=[NSMutableArray new];
            NSArray  *arrTitle=@[@"购买人姓名",@"联系方式",@"座位号",@"邮寄地址"];
            
            for (NSInteger i=0; i<4; i++) {
                
                id  textBlock=^(UITextField * _Nullable textField) {
                    UIButton *btnLab = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 30)];
                    [btnLab.titleLabel setFont:[UIFont systemFontOfSize:14]];
                    [btnLab.titleLabel setTextAlignment:NSTextAlignmentLeft];
                    [btnLab setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 50)];
                    [btnLab  setTitleColor:[UIColor  blackColor] forState:UIControlStateNormal];
                    [textField setLeftView:btnLab];
                    [textField setLeftViewMode:UITextFieldViewModeAlways];
                    [textField setPlaceholder:arrTitle[i]];
                    if (i==1) {
                        textField.keyboardType=UIKeyboardTypeDecimalPad;
                    };
                    
                    
                };
                
                [arrTextField addObject:textBlock];
                ;
            }
            
            
            CMCCIOTIGAlertControlCustomer  *alertControl=     [CMCCIOTTipsCenter showAlertTextFieldTitle:@"" message:@"输入备注" andTF:arrTextField cancelTitle:@"取消" cancelBlock:^(CMCCIOTIGAlertActionCustomer * _Nullable action) {
                
                
                ;
            } quireTitle:@"确定" quireBlock:^(CMCCIOTIGAlertActionCustomer * _Nullable action) {
                
                NSArray  *arrTextFields=action.textFields;
                
                Reamark  *remarkTem=[[Reamark  alloc]  init];
                
                UITextField  *textName=arrTextFields[0];
                remarkTem.FCustomerName=textName.text;
                
                UITextField  *textCustomerTel=arrTextFields[1];
                remarkTem.FCustomerTel=textCustomerTel.text;
                
                UITextField  *textSeatNum=arrTextFields[2];
                remarkTem.FCustomerSeatNum=textSeatNum.text;
                
                UITextField  *textAddress=arrTextFields[3];
                remarkTem.FCustomerAddress=textAddress.text;
                
                // 如果有特殊字符，不添加
                NSString  *strName=[textName.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
                NSString  *strAddress=  [textAddress.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
                
                if ([CMCCIOTIGUnity isIllegal:strName]||[CMCCIOTIGUnity isIllegal:strAddress]) {
                    [CMCCIOTTipsCenter showErrorWithStatus:ILLEGE_MESSAGE];
                    return;
                }
                
                for (Product   *product in arrGouWuFQty){
                    product.remark=remarkTem;
                    
                }
                [self.arrGouWu  addObjectsFromArray:arrGouWuFQty];
                [self gotoGouWuChe];
                
                
            } ];
            alertControl.messageAlignment=NSTextAlignmentLeft;
            
            ;
        }
        else{
            
            // 判断是否有特殊字符
            for (Product   *product in arrGouWuFQty){
                NSString  *fRemark=  [product.FRemark stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
                
                if ([CMCCIOTIGUnity isIllegal:fRemark]) {
                    product.FRemark =@"";
                }
            }

            
            [self.arrGouWu  addObjectsFromArray:arrGouWuFQty];
            [self gotoGouWuChe];
        }
        
    }
    else{
        
        [self gotoGouWuChe];
    }
    
}

-(void)gotoGouWuChe{
    
    
    
    for (int i=0; i<arrGouWu.count; i++) {
        
        Product  *product=arrGouWu[i];
        if (![product.FSaleType  isEqualToString: @"3" ]) {
            for (NSInteger j=(arrGouWu.count-1);j>i;j--) {
                Product  *productItem=arrGouWu[j]  ;
                
                if (![productItem.FSaleType  isEqualToString: @"3" ]) {
                    if (product.FID==productItem.FID) {
                        
                        product.FQty+=productItem.FQty;
                        [arrGouWu removeObject:productItem];
                        
                    }
                }
                
            }
            ;
        }
        
    }
    if (arrGouWu.count) {
        // 获取当前数据
        [NetWork    sumShoppingCart:self.arrGouWu callBack:^(id result, NSError *error) {
            
            if (error) {
                ;
            }
            else{
                
                NSDictionary  *resultData=result;
                [HangBanInfo currentHangBan].shoppingCartID=[NSString  stringWithFormat:@"%@",resultData[@"ShoppingCartID"]];
                [self.arrGouWu  removeAllObjects];
                // 清空当前数据位1的变量
                [self  modifyCurrentData];
    
                
            }
            ;
        }];

    }
    else{
    
        [CMCCIOTTipsCenter showErrorWithStatus:@"请选择商品"];
    
    }
    
}



- (IBAction)btnXianXiao:(id)sender {
    
    UIButton  *btnXianXiao=(UIButton  *) sender;
    btnXianXiao.selected=YES;
    UIButton  *btnTemZiTi=[self.view viewWithTag:101];
    btnTemZiTi.selected=NO;
    UIButton  *btnTemYouGou=[self.view viewWithTag:102];
    btnTemYouGou.selected=NO;
    self.type=xianXiao ;
    if (!arrMainData.count) {
        [CMCCIOTTipsCenter  showErrorWithStatus:@"暂无数据"];
    }
    [sale_tableView reloadData];
}
- (IBAction)btnZiTi:(id)sender {
    
    UIButton  *btnZiTi=(UIButton  *) sender;
    btnZiTi.selected=YES;
    UIButton  *btnTemXianXiao=[self.view viewWithTag:100];
    btnTemXianXiao.selected=NO;
    UIButton  *btnTemYouGou=[self.view viewWithTag:102];
    btnTemYouGou.selected=NO;
    
    self.type=ziTi ;
    if (!arrZiTi.count) {
        [CMCCIOTTipsCenter  showErrorWithStatus:@"暂无数据"];
    }
    [sale_tableView reloadData];
    
    
}

- (IBAction)btnYouGou:(id)sender {
    
    
    UIButton  *btnZYouGou=(UIButton  *) sender;
    btnZYouGou.selected=YES;
    UIButton  *btnTemXianXiao=[self.view viewWithTag:100];
    btnTemXianXiao.selected=NO;
    UIButton  *btnTemZiTI=[self.view viewWithTag:101];
    btnTemZiTI.selected=NO;
    self.type=youJI ;
    if (!arrYouGou.count) {
        [CMCCIOTTipsCenter  showErrorWithStatus:@"暂无数据"];
    }
    
    [sale_tableView reloadData];
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    [self.view  endEditing:YES];
    
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    
}



- (IBAction)pushClassCation:(id)sender {
    
    
    UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    
    ClassifiCation  *viewVC=  [mainStory instantiateViewControllerWithIdentifier:@"ClassifiCation"];
    viewVC.classBlock=^(id dicTem){
        
        [_textContent resignFirstResponder];
        _textContent.text=@"";
        
        NSMutableArray  *arrData;
        if (self.type==xianXiao) {
            
            arrData=arrMainData;
            ;
        }
        else if(self.type==ziTi){
            arrData=arrZiTi;
            
        }
        else{
            
            arrData=arrYouGou;
            
        }
        
        isSearch=YES;
        NSMutableArray  *arrSearchData=[NSMutableArray new];
        
        NSMutableArray  *arrResultData=[NSMutableArray  new];
        
        
        if ([dicTem[@"list"]  isKindOfClass:[NSArray  class]]) {
            
            NSArray  *arrList=dicTem[@"list"];
            if (arrList.count) {
                
                for (int i=0; i<arrList.count; i++) {
                    
                    NSDictionary  *dicTemPrama1=arrList[i];
                    
                    if ([dicTemPrama1[@"list"]  isKindOfClass:[NSArray  class]]) {
                        
                        NSArray  *arrListParama1=dicTemPrama1[@"list"];
                        if (arrListParama1.count) {
                            
                            for (int j=0; j<arrListParama1.count; j++) {
                                
                                NSDictionary  *dicTemParama2=arrListParama1[j];
                                
                                [arrSearchData  addObject:dicTemParama2[@"FCatogeryID"]]
                                ;
                            }
                            ;
                        }
                        else{
                            [arrSearchData  addObject:dicTemPrama1[@"FCatogeryID"]];
                            
                        }
                        
                    }
                    else{
                        
                        [arrSearchData  addObject:dicTemPrama1[@"FCatogeryID"]];
                        
                    }
                    
                    ;
                }
                
                ;
            }
            else{
                [arrSearchData  addObject:dicTem[@"FCatogeryID"]];
                
            }
            
        }
        else{
            
            dicTem[@"FCatogeryID"]?[arrSearchData  addObject:dicTem[@"FCatogeryID"]]:nil;
            
        }
        
        for (int i=0; i<arrSearchData.count; i++) {
            NSInteger  FCatogeryID=[arrSearchData[i]  integerValue];
            
            [arrData  enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                
                Product  *product=obj;
                
                if ( product.FCatogeryID== FCatogeryID) {
                    
                    [arrResultData addObject:product];
                    
                    ;
                }
                
            }];
            
        }
        
        if (arrResultData.count) {
            isSearch=YES;
            _arrSearch= arrResultData;
            
        }
        else{
            isSearch=NO;
            dicTem[@"FCatogeryID"]?[CMCCIOTTipsCenter showSuccessWithStatus:@"暂无此分类产品"]:nil;;
        }
        [sale_tableView  reloadData];
        
    };
    [self.navigationController pushViewController:viewVC animated:YES];
    
}


#pragma mark 跳转

- (IBAction)examineShoppingCar:(id)sender {
    
    SaleShoppingCart  *saleShoppingCart=[[UIStoryboard   storyboardWithName:@"Main" bundle:nil]  instantiateViewControllerWithIdentifier:@"SaleShoppingCart"];
    
    [self.navigationController  pushViewController:saleShoppingCart animated:YES];
    
}


@end
